# -- coding: utf-8 -- 
from django import forms

class ContactForm(forms.Form):
    subject = forms.CharField(max_length=100) #限制字段长度
    email = forms.EmailField(required=False,label='Your e-mail address')  #required表示该字段是否必填
    message = forms.CharField(widget=forms.Textarea)    #定义该字段的类型为Textarea
    
    #字段检验方法,方法名称以clean_开头，并以字段名称结束。
    def clean_message(self):
        message = self.cleaned_data['message']
        num_words = len(message.split())
        if num_words < 4:
            raise forms.ValidationError("Not enough words!")
        return message